package fr.persistence.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fr.form.Participation;
import fr.persistence.ManageParticipationPersistenceService;

@Service
public class ManageParticipationPersistenceServiceImpl 
	extends GenericDaoImpl<Participation, Integer> 
	implements ManageParticipationPersistenceService{

    @Autowired
	private SessionFactory sessionFactory;

	public ManageParticipationPersistenceServiceImpl() {
		super(Participation.class);
	}

	public ManageParticipationPersistenceServiceImpl(Class<Participation> type) {
		super(type);
	}
	
	@SuppressWarnings("unchecked")
	public List<Participation> readByParam(List<Integer> pStatutParticipationList, Integer pUserId,
			Integer pApplicationId) {
		Session s = sessionFactory.getCurrentSession();
		
		Criteria criteres = s.createCriteria(Participation.class);

		if(pStatutParticipationList != null){
			criteres.add(Restrictions.in("statutParticipation",pStatutParticipationList));
		}

		if(pUserId != null){
			criteres.add(Restrictions.eq("idUser",pUserId));
		}

		if(pApplicationId != null){
			criteres.add(Restrictions.eq("idApplication",pApplicationId));
		}
			
		return (List<Participation>) criteres.list();
	}

}
